package yf.mall.entity;


import lombok.Setter;
import lombok.Getter;
import yf.mall.common.Const;
import yf.mall.enums.CouponStatusEnum;

import java.io.Serializable;
import java.util.Date;

import java.math.BigDecimal;

/**
 * 卡券实体
 * 表名 coupon
 *
 *
 * 
 * @date ${datetime}
 */
@Setter
@Getter
public class CouponEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    //
    private Long id;
        //用户
    private Long userId;
        //创建时间
    private Date createTime;
        //起止时间
    Date[] createTimes;
        //过期时间
    private Date expireTime;
        //起止时间
    Date[] expireTimes;
        //产生单号
    private String fromOrderNo;
        //使用单号
    private String userOrderNo;
        //面值
    private BigDecimal mount;
        //详情
    private String info;
        //可使用产品
    private String goods;
        //ENUM-状态:"NEW-未使用","USED-已使用"
    private Integer status;
    
    public CouponEntity(){

    }


    //可以用
    public Boolean isAct(){
        return !this.isUsed()&&!this.isNot();
    }


    //过期或者已经使用
    public Boolean isUsed(){
       return CouponStatusEnum.NEW.getIndex()!=this.getStatus()||this.getExpireTime().before(new Date());
    }

    //未到账
    public Boolean isNot(){
        long exp = 1000*60*60*24* Const.BACK_DAY;
        return new Date().getTime()-this.getCreateTime().getTime()<exp;
    }


    public CouponEntity(Long userId, Date createTime, Date expireTime, String fromOrderNo, BigDecimal mount, String info, Integer status) {
        this.userId = userId;
        this.createTime = createTime;
        this.expireTime = expireTime;
        this.fromOrderNo = fromOrderNo;
        this.mount = mount;
        this.info = info;
        this.status = status;
    }
}
